﻿using System.Linq;
using Coder.Workflow;

namespace Fee.Orders.DesignWorkflow
{
    public class BudgetOrderWorkTask : WorkTask
    {
        protected override bool PreCondition(ProcessInstance instalc)
        {
            var delePro = (BudgetOrder) instalc;

            if (Name == BudgetOrder.DesignPlanCostPlanStep3 &&
                delePro.ConstructionTask.Station.Type == StationType.FamilyCoverage)
            {
                //4、家客预覆盖站点，需判断是否超标，如果超标需推送至工程建设中心审批
                //  判断条件：总投资（管道 + 光缆 + 设备）/ 户数 > 230.00

                var totalAmount = delePro.PlanCosts.Sum(f => f.TotalAmount);
                var avg = totalAmount / delePro.ConstructionTask.Station.UsersNumber;
                return avg > 230;
            }

            //只要不是第三步，度无条件进入
            return Name != BudgetOrder.DesignPlanCostPlanStep3;
        }
    }
}